<?php

/**
 * Controller class
 * 
 * @package DeadTouch AAC
 * @version 0.0.1
 * @author Kofel <kofels@gmail.com>
 * @copyright 2008 (C) by Kofel
 * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
 * @todo future: :D
 */
 
class controllerLayer
{
	public function load( $c = NULL, $a = NULL )
	{
		if( !file_exists( 'controllers/.' ) )
		{
			throw new KernelException('<strong>controllers/</strong> doesn\'t exist, please fix it.');
		}
		
		if( !$c )
		{
			$Controller = ( $_GET['c'] ) ? $_GET['c'] : 'index';
			$Action = ( $_GET['a'] ) ? $_GET['a'] : 'index';
		}
		else
		{
			$Controller = $c;
			$Action = ( $a ) ? $a : 'index';
		}
		
		
		if( file_exists( 'controllers/controller.' . $Controller . '.php' ) )
		{
			require_once 'controllers/controller.' . $Controller . '.php';
			$_t = $Controller . 'Controller';
			
			if( class_exists( $_t ) )
			{
				$_t = new $_t;
				
				if( method_exists( $_t, $Action ) )
				{
					$_t->$Action();
					return true;
				}
				
				return false;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
}
?>